package cn.jdy.platform.tag;

import cn.jdy.framework.util.SpringContextUtils;
import cn.jdy.platform.entity.ConfValue;
import cn.jdy.platform.service.ConfService;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
 * 获取配置信息
 * 1、获取配置信息
 * 2、循环输出页面
 *
 * @description :
 * @author: zhaiguangtao
 * @data: 2010-8-9
 */
public class ConfIteratorTag extends SimpleTagSupport implements java.io.Serializable{
	private static final long serialVersionUID = 1L;
	private String typeid;// 对应配置项目 typeid
	private Long pid;
	private String type;// str 单一字符串输出,object
	private String var;
	private int limitMax=10000; //默认一次最多查询记录数
	private String style;// 显示样式

	@Override
	public void doTag() throws JspException, IOException {
		Iterator<ConfValue> ite = null;
		ConfService conf = SpringContextUtils.getBean(ConfService.class);
		if("object".equals(type)) {// 输出
			List<ConfValue> list = conf.queryByType(Integer.parseInt(typeid),pid,limitMax);
			ite = list.iterator();
			// 进行迭代
			while (ite.hasNext()) {
				Object obj = ite.next();
				getJspContext().setAttribute(var, obj);
				//输出标签体
				getJspBody().invoke(null);
			}
		}
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getTypeid() {
		return typeid;
	}

	public void setTypeid(String typeid) {
		this.typeid = typeid;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public int getLimitMax() {
		return limitMax;
	}

	public void setLimitMax(int limitMax) {
		this.limitMax = limitMax;
	}

	public Long getPid() {
		return pid;
	}

	public void setPid(Long pid) {
		this.pid = pid;
	}

}
